package net.atomtree.util;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

public class CreateConnection {
	

	private static String HBASE_ZOOKEEPER_QUORUM = null;
	
	private static String HBASE_ZOOKEEPER_PROPERTY_CLIENTPORT = null;
	
	private static String HBASE_MASTER = null;
	
	
	
	
	static{
        try
        {
            InputStream is = new BufferedInputStream(new FileInputStream(System.getProperty("user.dir")+"/conf/hbaseconf.properties"));
            Properties p = new Properties();
            p.load(is);
            HBASE_ZOOKEEPER_QUORUM = p.getProperty("hbase.zookeeper.quorum");
            HBASE_ZOOKEEPER_PROPERTY_CLIENTPORT = p.getProperty("hbase.zookeeper.property.clientPort");
            HBASE_MASTER = p.getProperty("hbase.master");   
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        
    }
	
	
	
	/*
	 * ����һ��hbase�����Ӷ���Connection����  �����Ի��hbase�ı����Table���߹������Admin
	 */
	
	
	
	public Connection getConn(){
		Configuration conf = HBaseConfiguration.create();
		conf.set("hbase.zookeeper.quorum", HBASE_ZOOKEEPER_QUORUM);
		conf.set("hbase.zookeeper.property.clientPort", HBASE_ZOOKEEPER_PROPERTY_CLIENTPORT);
		conf.set("hbase.master", HBASE_MASTER);
		Connection conn =null;
		try{
			System.out.println("**********��ʼ��������**********");
			conn = ConnectionFactory.createConnection(conf);
			System.out.println("**********���ӽ���**************");
		}catch(IOException e){	
			System.out.println("��������ʧ��");
		}		
		return  conn;
		
	}
	
	


}